package com.baihan.angus.app.game.basic.bindingAdp;

import android.widget.ImageView;

import androidx.databinding.BindingAdapter;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

public final class ImageViewBindingAdp {

    @BindingAdapter(value = {"onUrlRec", "defaultImageRecordId"}, requireAll = false)
    public static void setImageUrl(ImageView imageView, String imageUrl, int defaultImageRecordId) {
        Glide.with(imageView.getContext()).load(imageUrl).apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
                .error(Glide.with(imageView.getContext()).load(defaultImageRecordId))
                .into(imageView);

    }

    @BindingAdapter(value = {"src"}, requireAll = false)
    public static void setImageUrl(ImageView imageView, int imageRec) {
       imageView.setImageResource(imageRec);

    }

}
